using System.Collections;
using UnityEngine;

public class BattleAttack_Siplett_Splash : MonoBehaviour
{
	public bool EnableRandomFlipVarient = true;

	public bool EnableDelayedTimer;

	[SerializeField]
	private GameObject Droplet;

	[SerializeField]
	private Transform DropletSpawnPosition;

	[SerializeField]
	private float DropletSpawnRadius;

	[SerializeField]
	private Transform DropletEndArcPosition;

	[SerializeField]
	private Animator CupAnimator;

	[SerializeField]
	private AudioClip[] SplashSounds;

	[SerializeField]
	private SpriteRenderer CupRenderer;

	[SerializeField]
	private SpriteRenderer LiquidRenderer;

	[SerializeField]
	private int DropletsPerSplash = 5;

	[SerializeField]
	private int AmountOfSplashes = 5;

	[SerializeField]
	private float AttackTime = 7.5f;

	private bool HasRanGuaranteedDroplet;

	private void Awake()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		((MonoBehaviour)this).StartCoroutine(SplashLoop());
		if (Random.Range(0, 2) == 0 && EnableRandomFlipVarient)
		{
			((Component)this).transform.localScale = new Vector3(-1f, 1f, 1f);
		}
		CupRenderer.color = new Color(1f, 1f, 1f, 0f);
		LiquidRenderer.color = new Color(1f, 1f, 1f, 0f);
		CutsceneUtils.FadeInSprite(CupRenderer);
		CutsceneUtils.FadeInSprite(LiquidRenderer);
	}

	private IEnumerator SplashLoop()
	{
		yield return (object)new WaitForSeconds(0.25f);
		int remainingSplashes = AmountOfSplashes;
		if (EnableDelayedTimer)
		{
			yield return (object)new WaitForSeconds(AttackTime / (float)AmountOfSplashes / 2f);
		}
		while (remainingSplashes > 1)
		{
			yield return null;
			((MonoBehaviour)this).StartCoroutine(LaunchDroplet());
			yield return (object)new WaitForSeconds(AttackTime / (float)AmountOfSplashes);
			remainingSplashes--;
			HasRanGuaranteedDroplet = false;
		}
	}

	private IEnumerator LaunchDroplet()
	{
		CupAnimator.Play("Siplett_BattleAttack_CupSplash", -1, 0f);
		yield return (object)new WaitForSeconds(0.24150002f);
		BattleSystem.PlayBattleSoundEffect(SplashSounds[Random.Range(0, SplashSounds.Length)], Random.Range(0.55f, 0.7f), Random.Range(0.75f, 1.25f));
		for (int i = 0; i < DropletsPerSplash; i++)
		{
			Vector2 val = Vector2.op_Implicit(DropletSpawnPosition.position) + Random.insideUnitCircle * DropletSpawnRadius;
			GameObject val2 = Object.Instantiate<GameObject>(Droplet, Vector2.op_Implicit(val), Quaternion.identity, BattleSystem.Instance.Holder_Bullets.transform);
			val2.transform.localScale = Vector3.one * Random.Range(0.85f, 1f);
			if (!HasRanGuaranteedDroplet)
			{
				HasRanGuaranteedDroplet = true;
				((Object)val2).name = "dadada";
				float num = Mathf.Abs(BattleSystem.Instance.BattleBox.transform.position.x - ((Component)Battle_PlayerSoul.Instance).transform.position.x) / 2f;
				val2.GetComponent<BattleAttack_Siplett_DropletArc>().JumpEndPos = Vector2.op_Implicit(new Vector2(((Component)Battle_PlayerSoul.Instance).transform.position.x - num, DropletEndArcPosition.position.y));
				val2.GetComponent<BattleAttack_Siplett_DropletArc>().DisableRandomOffsetMarkiplier = true;
			}
			else
			{
				val2.GetComponent<BattleAttack_Siplett_DropletArc>().JumpEndPos = DropletEndArcPosition.position;
			}
		}
	}

	private void OnDrawGizmosSelected()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)DropletSpawnPosition != (Object)null)
		{
			Gizmos.color = Color.red;
			Gizmos.DrawWireSphere(DropletSpawnPosition.position, DropletSpawnRadius);
		}
	}
}
